///////////////////////////////////////////////////////////////////////////////
// Project: Hoyo Client Game
//
// hy_battle_logic.h
// Created: 2013-7-15
// Author: Like Cheng
///////////////////////////////////////////////////////////////////////////////
#include "hy_includes.h"

#include "hy_battle_system/hy_battle_data.h"


class hy_battle_unit;
class hy_battle_data;
class hy_server_skill_data;
class common_skill_data;

typedef std::map< int, hy_battle_data* > hy_battle_data_map;
class hy_battle_logic : public hy_object
{
public:
	hy_battle_logic();
	virtual ~hy_battle_logic();

	static hy_battle_logic*		instance();
	static void					purge_instance();
public:

public:

	hy_battle_data*				create_battle( int player_id, int copy_template_id );
	int							create_monster_battle_unit( int battle, int copy_id, int nums );
	void						trigger_skill_exec( hy_battle_data* bd );
	void						trigger_skill_add_logic( common_skill_data* csd,  hy_battle_unit* own, hy_battle_data* bd );

	int							create_player_battle_unit( int battle_id, int player_id );
	void						create_battle_progress( int _battle_id );
	void						create_battle_send_skill_sort( int battle_id );
	hy_battle_unit*				get_send_skill_battle_unit( int battle_id );
	

	void						add_battle_data_map( hy_battle_data*, bool update = true );
	void						remove_battle_data_map( int battle_id );

	hy_battle_unit_map			get_enemy_battle_unit_map( int battle_id, hy_battle_unit* own );
	hy_battle_unit_map			get_canattack_enemy_battle_unit_map( int battle_id, hy_battle_unit* own, int_vec& iv );

	hy_battle_data*				get_battle_data( int battle_id );
	int_vec						get_player_list( int battle_id );

	void						battle_begin( int battle_id );
	void						battle_state_proc( int battle_id );
	int							battle_round_proc( hy_battle_data* bd, int round );
	bool						battle_complate_proc( hy_battle_data*, int& pos );
	bool						battle_progress_skill( int battle_id, int skill_id,int skill_level, hy_battle_unit* own, class hy_tag_skill_pro* tsp );


private:
	hy_battle_data_map			m_battle_data_map;

	void	sort_battle_unit( hy_battle_unit_map* tmap, std::vector< hy_battle_unit* > &buv, int type );
	bool	battle_map_by_select_type( hy_battle_data* bd1, hy_battle_unit_map* tmap, hy_battle_unit* bd2, hy_server_skill_data* skill_data );
};